package com.nursing.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.nursing.Dao.NurseDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.nursing.bean.Nurse;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class NurseService {
    private final NurseDao nurseDao;

    @Autowired
    public NurseService(NurseDao nurseDao) {
        this.nurseDao = nurseDao;
    }

    public void deleteNurse(Integer id) {
        nurseDao.delete(id);
    }

    public void updateNurse(Nurse nurse) {
        nurseDao.update(nurse);
    }

    public void addNurse(Nurse nurse) {
        nurse.setPassword("123456");
        nurse.setCreatedAt(LocalDateTime.now());
        nurseDao.insert(nurse);
    }

    public PageInfo<Nurse> list(int page,int size) {
        PageHelper.startPage(page, size);
        List<Nurse> nurses = nurseDao.getAll();
        return new PageInfo<>(nurses);
    }

    public void bindTask(int nurseId, int elderId,String taskDetails) {
        nurseDao.bindTask(nurseId, elderId, taskDetails, 0, LocalDateTime.now().toString());
    }

    public Nurse getNurseById(Integer id) {
        return nurseDao.getById(id);
    }

    public Integer getNurseCount() {
        return nurseDao.getCount();
    }

    public Nurse login(String username, String password) {
        return nurseDao.verify(username, password);
    }

    public void changePassword(Nurse nurse) {
        nurseDao.changePassword(nurse);
    }
}
